<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Services\CategoryService;
use Illuminate\Http\Request;
use Inertia\Inertia;

/**
 * 前台分类控制器
 * 
 * 职责：
 * - 处理前台分类相关的HTTP请求
 * - 调用 CategoryService 处理业务逻辑
 * - 返回视图
 */
class CategoryController extends Controller
{
    /**
     * 分类服务
     * 
     * @var CategoryService
     */
    protected CategoryService $categoryService;

    /**
     * 构造器
     */
    public function __construct(CategoryService $categoryService)
    {
        $this->categoryService = $categoryService;
    }

    /**
     * 显示分类页面
     */
    public function show(Category $category, Request $request)
    {
        // 调用服务层获取分类下的已发布文章
        $posts = $this->categoryService->getCategoryPosts(
            $category,
            $request->only(['search']),
            9
        );

        return Inertia::render('Blog/Category', [
            'category' => $category,
            'posts' => $posts
        ]);
    }
} 